package com.orientsec.autotest.project.system.cases.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.cases.domain.Cases;
import com.orientsec.autotest.project.system.cases.service.ICasesService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 组合案例设置信息操作处理
 * 
 * @author autotest
 * @date 2020-02-19
 */
@Controller
@RequestMapping("/system/cases")
public class CasesController extends BaseController
{
    private String prefix = "system/cases";
	
	@Autowired
	private ICasesService casesService;
	
	@RequiresPermissions("system:cases:view")
	@GetMapping()
	public String cases()
	{
	    return prefix + "/cases";
	}
	
	/**
	 * 查询组合案例设置列表
	 */
	@RequiresPermissions("system:cases:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Cases cases)
	{
		startPage();
        List<Cases> list = casesService.selectCasesList(cases);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出组合案例设置列表
	 */
	@RequiresPermissions("system:cases:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cases cases)
    {
    	List<Cases> list = casesService.selectCasesList(cases);
        ExcelUtil<Cases> util = new ExcelUtil<Cases>(Cases.class);
        return util.exportExcel(list, "cases");
    }
	
	/**
	 * 新增组合案例设置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存组合案例设置
	 */
	@RequiresPermissions("system:cases:add")
	@Log(title = "组合案例设置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Cases cases)
	{		
		return toAjax(casesService.insertCases(cases));
	}

	/**
	 * 修改组合案例设置
	 */
	@GetMapping("/edit/{casesType}")
	public String edit(@PathVariable("casesType") String casesType, ModelMap mmap)
	{
		Cases cases = casesService.selectCasesById(casesType);
		mmap.put("cases", cases);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存组合案例设置
	 */
	@RequiresPermissions("system:cases:edit")
	@Log(title = "组合案例设置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Cases cases)
	{		
		return toAjax(casesService.updateCases(cases));
	}
	
	/**
	 * 删除组合案例设置
	 */
	@RequiresPermissions("system:cases:remove")
	@Log(title = "组合案例设置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(casesService.deleteCasesByIds(ids));
	}
	
}
